package nio.buffter;

import java.nio.IntBuffer;
//只读
public class buffterTest3 {
    public static void main(String[] args) {
        //大小为5 类型为int的buffer
        IntBuffer allocate = IntBuffer.allocate(5);
        //存放
        for (int i = 0;i < allocate.capacity(); i++){
            allocate.put(i * 2);
            System.out.println("posion"+allocate.position());
        }
        //取
        allocate.flip();//读写切换

        IntBuffer intBuffer = allocate.asReadOnlyBuffer();
        System.out.println(intBuffer.getClass());
        while (intBuffer.hasRemaining()){
            System.out.println("data"+intBuffer.get()+" posion"+intBuffer.position());
        }

        //设为只读会 写会报错 ReadOnlyBufferException
        intBuffer.put(1);
    }
}
